package com.chb.controller;

import com.chb.model.vo.LoginVo;
import com.chb.model.vo.Result;
import com.chb.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 陈海彬
 * @date: Created in 2023/9/25 15:21
 * @description: 登录控制器
 * @modified By:
 * @version: 1.0
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private StaffService staffService;

    /**
     * @param loginVo 登录实体类
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 用户登录
     * @create time: 2023/9/25 15:39
     */
    @PostMapping
    public Result userLogin(@RequestBody LoginVo loginVo) {
        Result result = staffService.selectByNameAndPwd(loginVo.getUsername(), loginVo.getPassword());
        return result;
    }

    /**
     * @create by: 陈海彬
     * @description: 登录成功跳转到主页面
     * @create time: 2023/9/25 19:46
     */
    /*@RequestMapping("/index")
    public String toIndex() {
        return "index";
    }*/

    /**
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 获取用户信息
     * @create time: 2023/9/27 16:07
     */
    @PostMapping("/info")
    public Result getUserInfo() {
        return staffService.getUserInfo();
    }

    /**
     * @param oldPassWord 用户输入的旧密码
     * @param newPassWord 新密码
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 修改用户密码
     * @create time: 2023/10/10 9:49
     */
    @PostMapping("/updatePassWord")
    public Result updatePassWord(String oldPassWord, String newPassWord) {
        return staffService.updatePassWord(oldPassWord, newPassWord);
    }

    /**
     * @param
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 退出登录
     * @create time: 2023/10/10 10:19
     */
    @PostMapping("/loginOut")
    public Result loginOut() {
        return staffService.loginOut();
    }

    /**
     * @param phone 要验证的手机号
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 发送验证码
     * @create time: 2023/10/11 12:19
     */
    @PostMapping("/sendValidateCode")
    public Result sendValidateCode(String phone) {
        return staffService.sendValidateCode(phone);
    }

    /**
     * @param phone 手机号
     * @param code  验证码
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 校验登录
     * @create time: 2023/10/11 15:34
     */
    @PostMapping("/identityVerification")
    public Result identityVerification(String phone, String code) {
        return staffService.identityVerification(phone, code);
    }
}